package models.statistics;

import exceptions.InvalidParameterException;
import play.db.jpa.GenericModel;

public abstract class CompressionStatsBase extends GenericModel{
    protected static long calcReducedValue(long sourceValue, int reductionRate) throws InvalidParameterException {
        if (reductionRate <= 0)
            throw new InvalidParameterException("reductionRate", String.valueOf(reductionRate));
        return sourceValue / reductionRate;
    }

    protected static float calcCompressionRate(long sourceTextSize, long compressedTextSize) throws InvalidParameterException {
        if (sourceTextSize == 0)
            throw new InvalidParameterException("sourceFileSize", String.valueOf(sourceTextSize));
        return ((float) compressedTextSize / sourceTextSize) * 100;
    }
}
